package com.spzx.cart.api.factory;

import com.spzx.cart.api.RemoteCartService;
import com.spzx.cart.api.domain.CartInfo;
import com.spzx.common.core.domain.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * ClassName: RemoteCartFallbackFactory
 * Package: com.spzx.cart.api
 * Description:
 *
 * @Author 咚咚小圆帽
 * @Create 2025/3/28 20:33
 * @Version 1.0
 */
@Component
@Slf4j
public class RemoteCartFallbackFactory implements FallbackFactory<RemoteCartService> {


    @Override
    public RemoteCartService create(Throwable cause) {

        log.error("购物车服务调用失败:{}", cause.getMessage());
        return new RemoteCartService() {
            @Override
            public R<List<CartInfo>> getCartCheckedList(Long userId, String source) {
                return R.fail("获取用户购物车选中数据失败:" + cause.getMessage());
            }

            @Override
            public R<Boolean> deleteCartCheckedList(Long userId, String source) {
                return R.fail("删除用户购物车选中数据失败:" + cause.getMessage());
            }

            @Override
            public R<Boolean> updateCartPrice(Long userId, String source) {
                return R.fail("更新购物车价格失败:" + cause.getMessage());
            }
        };
    }
}
